using System;
using System.ComponentModel;
using System.Globalization;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;

[assembly: TagPrefix("Azad.BCL.CustomGrid", "CustomGrid")]
namespace Azad.BCL.CustomGrid
{

    public delegate void ShowHideEventHandler(object sender, EventArgs e);
    [ToolboxData("<{0}:CustomGrid runat=server></{0}:CustomGrid>")]
    public partial class CustomGrid : GridView
    {

        /// <summary>
        /// Show and Hide particular column runtime
        /// </summary>
        /// <param name="headerRow"></param>
        /// <param name="field"></param>
        #region Show Hide Columns
        private readonly object EventShowHideCommand = new object();
        [Category("Extend GridView Events"), Description("ExtededGridView_OnFilterCommand")]
        public event ShowHideEventHandler ShowHideCommand
        {
            add
            {
                base.Events.AddHandler(EventShowHideCommand, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventShowHideCommand, value);
            }
        }
        protected virtual void AddShowHideColumn(GridViewRow headerRow, DataControlField[] field)
        {

            DropDownList GridView1ShowHideColumns = this.NamingContainer.FindControl(ShowHideDropDown) as DropDownList;
            if (GridView1ShowHideColumns != null)
            {
                GridView1ShowHideColumns.SelectedIndexChanged += new EventHandler(GridView1ShowHideColumns_SelectedIndexChanged);
                if (!Page.IsPostBack)
                {
                    hiddenColumnIndexes = new List<int>();
                }
                for (int columnIndex = 0; columnIndex < Columns.Count; columnIndex++)
                {
                    if (Columns[columnIndex] is CustomBoundField)
                    {
                        CustomBoundField customBoundField = Columns[columnIndex] as CustomBoundField;
                        if (!customBoundField.isMandatory)
                        {
                            LiteralControl ltlBreak = new LiteralControl(Text[columnIndex]);


                            LinkButton hideLink = new LinkButton();
                            hideLink.CommandName = "hideCol";
                            hideLink.CommandArgument = columnIndex.ToString();
                            hideLink.Text = "- ";//+ headerRow.Cells[columnIndex].Text;

                            hideLink.CssClass = "gvHideColLink";
                            hideLink.Attributes.Add("title", "Hide Column");
                            hideLink.Command += new CommandEventHandler(hideLink_Command);
                            // Add the "Hide Column" LinkButton to the header cell

                            
                            headerRow.Cells[columnIndex].Controls.Add(hideLink);

                            headerRow.Cells[columnIndex].Controls.Add(ltlBreak);

                            // If there is column header text then
                            // add it back to the header cell as a label
                            if (headerRow.Cells[columnIndex].Text.Length > 0)
                            {
                                Label columnTextLabel = new Label();
                                columnTextLabel.Text = headerRow.Cells[columnIndex].Text;
                                headerRow.Cells[columnIndex].Controls.Add(columnTextLabel);
                            }
                        }
                    }
                }
            }
        }

        void hideLink_Command(object sender, CommandEventArgs e)
        {
            this.Columns[Convert.ToInt32(e.CommandArgument)].Visible = false;
            hiddenColumnIndexes = hiddenColumnIndexes;
            hiddenColumnIndexes.Add(Convert.ToInt32(e.CommandArgument));
            ShowHideEventHandler handler = (ShowHideEventHandler)base.Events[EventShowHideCommand];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private List<int> hiddenColumnIndexes
        {
            get
            {
                return ViewState["hiddenColumnIndexes"] == null ? new List<int>() : (List<int>)ViewState["hiddenColumnIndexes"];
            }
            set
            {
                ViewState["hiddenColumnIndexes"] = value;
            }
        }

        void SetupShowHideColumns()
        {
            DropDownList GridView1ShowHideColumns = this.NamingContainer.FindControl(ShowHideDropDown) as DropDownList;

            if (GridView1ShowHideColumns != null)
            {
                GridView1ShowHideColumns.Items.Clear();

                if (hiddenColumnIndexes.Count > 0)
                {
                    GridView1ShowHideColumns.Visible = true;
                    GridView1ShowHideColumns.Items.Add(new ListItem("-Show Column-", "-1"));
                    GridView1ShowHideColumns.SelectedIndexChanged += new EventHandler(GridView1ShowHideColumns_SelectedIndexChanged);

                    foreach (int i in hiddenColumnIndexes)
                        GridView1ShowHideColumns.Items.Add(new ListItem(this.Columns[i].HeaderText, i.ToString()));
                }
                else
                {
                    GridView1ShowHideColumns.Visible = false;
                }
            }
        }

        void GridView1ShowHideColumns_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList GridView1ShowHideColumns = sender as DropDownList;
            if (GridView1ShowHideColumns.SelectedIndex > 0)
            {
                int columnIndex = int.Parse(GridView1ShowHideColumns.SelectedValue);
                hiddenColumnIndexes.Remove(columnIndex);
                this.Columns[columnIndex].Visible = true;
                SetupShowHideColumns();
            }
            ShowHideEventHandler handler = (ShowHideEventHandler)base.Events[EventShowHideCommand];
            if (handler != null)
            {
                handler(this, e);
            }

        }
        #endregion

        #region Pager
        //protected virtual void InitializeTopPager(GridViewRow row,
        //    int columnSpan,
        //    PagedDataSource pagedDataSource)
        //{
        //    TableCell cell = new TableCell();
        //    if (columnSpan > 1)
        //    {
        //        cell.ColumnSpan = columnSpan;
        //    }
        //    Literal ltrlSpan = new Literal();
        //    ltrlSpan.Text = "<span style='float:left'>&nbsp;" +
        //        pagedDataSource.DataSourceCount.ToString() +
        //        "&nbsp;record(s)&nbsp;found.</span>";
        //    cell.Controls.Add(ltrlSpan);
        //    row.Cells.Add(cell);
        //}

        //protected virtual void InitializeBottomPager(GridViewRow row,
        //    int columnSpan,
        //    PagedDataSource pagedDataSource)
        //{
        //    TableCell goToCell = new TableCell();
        //    goToCell.Style.Add(HtmlTextWriterStyle.Width, "100%");

        //    Table pagerTable = (Table)row.Cells[0].Controls[0];
        //    pagerTable.Rows[0].Cells.Add(goToCell);

        //    Literal ltrlSpanBegin = new Literal();
        //    ltrlSpanBegin.Text = "<span style='float:right'>Page&nbsp;";

        //    if (m_txtPageNo == null)
        //    {
        //        m_txtPageNo = new TextBox();
        //        m_txtPageNo.Width = new Unit(20);
        //        m_txtPageNo.Style.Add("height", "10px");
        //        m_txtPageNo.Font.Size = new FontUnit("10px");
        //        m_txtPageNo.CssClass = this.PagerStyle.CssClass;
        //    }

        //    Literal ltrlText = new Literal();
        //    ltrlText.Text = "&nbsp;of&nbsp;" + PageCount.ToString();

        //    Button btnGo = new Button();
        //    btnGo.Text = "Go";
        //    btnGo.CommandName = "Page1";
        //    btnGo.CommandArgument = "2";
        //    btnGo.ID = "ctl_PageIndex";
        //    btnGo.Height = new Unit("16px");
        //    btnGo.Font.Size = new FontUnit("10px");
        //    btnGo.CssClass = this.PagerStyle.CssClass;
        //    if (this.PagerStyle.ForeColor != null)
        //    {
        //        btnGo.Style.Add(HtmlTextWriterStyle.Color,
        //            this.PagerStyle.ForeColor.ToString());
        //    }

        //    Literal ltrlSpanEnd = new Literal();
        //    ltrlSpanEnd.Text = "</span>";

        //    goToCell.Controls.Add(ltrlSpanBegin);
        //    goToCell.Controls.Add(m_txtPageNo);
        //    goToCell.Controls.Add(ltrlText);
        //    goToCell.Controls.Add(btnGo);
        //    goToCell.Controls.Add(ltrlSpanEnd);
        //}

        #endregion

        /// <summary>
        /// Gets or sets a value indicating whether [custom theme].
        /// </summary>
        /// <value><c>true</c> if [custom theme]; otherwise, <c>false</c>.</value>
        public bool CustomTheme
        {
            get;
            set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref=""></see>
        ///   class.
        /// </summary>
        public CustomGrid()
        {
            AssignCss();
        }

        /// <summary>
        /// Assigns the CSS.
        /// </summary>
        private void AssignCss()
        {
            HeaderStyle.CssClass = "H2hGH";
            FooterStyle.CssClass = "H2hGF";
            RowStyle.CssClass = "H2hGItm";
            AlternatingRowStyle.CssClass = "H2hGAItm";

            AutoGenerateColumns = false;
            BorderWidth = Unit.Pixel(1);
            //BorderColor = System.Drawing.Color.FromArgb(0xC0C0C0);
            GridLines = GridLines.None;
            CssClass = "H2hG";

            AllowPaging = true;
            AllowSorting = false;
            UseCustomPager = true;

            PagerStyle.CssClass = "H2hGP";
            PagerSettings.PageButtonCount = 10;

            PagerSettings.NextPageText = "Next";
            PagerSettings.PreviousPageText = "Previous";
            PagerSettings.FirstPageText = "";
            PagerSettings.LastPageText = "";
        }

        /// <summary>
        /// Renders the Web server control content to the client's browser using the specified <see cref="T:System.Web.UI.HtmlTextWriter"/> object.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> used to render the server control content on the client's browser.</param>
        protected override void Render(HtmlTextWriter writer)
        {
            AssignCss();
            base.Render(writer);
        }

        /// <summary>
        /// Creates the control hierarchy used to render the <see cref="T:System.Web.UI.WebControls.GridView"/> control using the specified data source.
        /// </summary>
        /// <param name="dataSource">An <see cref="T:System.Collections.IEnumerable"/> that contains the data source for the <see cref="T:System.Web.UI.WebControls.GridView"/> control.</param>
        /// <param name="dataBinding">true to indicate that the child controls are bound to data; otherwise, false.</param>
        /// <returns>The number of rows created.</returns>
        /// <exception cref="T:System.Web.HttpException">
        /// 	<paramref name="dataSource"/> returns a null <see cref="T:System.Web.UI.DataSourceView"/>.
        /// -or-
        /// <paramref name="dataSource"/> does not implement the <see cref="T:System.Collections.ICollection"/> interface and cannot return a <see cref="P:System.Web.UI.DataSourceSelectArguments.TotalRowCount"/>.
        /// -or-
        /// <see cref="P:System.Web.UI.WebControls.GridView.AllowPaging"/> is true and <paramref name="dataSource"/> does not implement the <see cref="T:System.Collections.ICollection"/> interface and cannot perform data source paging.
        /// -or-
        /// <paramref name="dataSource"/> does not implement the <see cref="T:System.Collections.ICollection"/> interface and <paramref name="dataBinding"/> is set to false.
        /// </exception>
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            int numRows = base.CreateChildControls(dataSource, dataBinding);

            //no data rows created, create empty table if enabled
            if (numRows == 0 && ShowWhenEmpty)
            {
                //create table
                Table table = new Table();
                table.CssClass = CssClass;
                table.ID = ID;

                //convert the exisiting columns into an array and initialize
                DataControlField[] fields = new DataControlField[Columns.Count];
                Columns.CopyTo(fields, 0);

                if (ShowHeader)
                {
                    //create a new header row
                    GridViewRow headerRow = base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);

                    InitializeRow(headerRow, fields);
                    table.Rows.Add(headerRow);
                }

                //create the empty row
                GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);

                TableCell cell = new TableCell();
                int count = 0;
                foreach (DataControlField col in Columns)
                {
                    if (col.Visible == true)
                    {
                        count++;
                    }
                }
                //cell.ColumnSpan = Columns.Count;
                cell.ColumnSpan = count;
                cell.Width = Unit.Percentage(100);
                cell.Height = Unit.Pixel(20);
                cell.CssClass = RowStyle.CssClass;
                if (!String.IsNullOrEmpty(EmptyDataText))
                    cell.Controls.Add(new LiteralControl(EmptyDataText));

                if (EmptyDataTemplate != null)
                    EmptyDataTemplate.InstantiateIn(cell);

                emptyRow.Cells.Add(cell);
                table.Rows.Add(emptyRow);

                if (ShowFooter)
                {
                    //create footer row
                    GridViewRow footerRow = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);

                    InitializeRow(footerRow, fields);
                    table.Rows.Add(footerRow);
                }

                Controls.Clear();
                Controls.Add(table);


            }

            return numRows;
        }

        /// <summary>
        /// Initializes the pager row displayed when the paging feature is enabled.
        /// </summary>
        /// <param name="row">A <see cref="T:System.Web.UI.WebControls.GridViewRow"/> that represents the pager row to initialize.</param>
        /// <param name="columnSpan">The number of columns the pager row should span.</param>
        /// <param name="pagedDataSource">A <see cref="T:System.Web.UI.WebControls.PagedDataSource"/> that represents the data source.</param>
        protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
        {
            if (AllowPaging)
            {
                pagedDataSource.AllowCustomPaging = true;
                pagedDataSource.VirtualCount = VirtualItemCount;
                pagedDataSource.CurrentPageIndex = CurrentPageIndex;
            }

            if (UseCustomPager)
            {
                // This method is called to initialise the pager on the grid. We intercepted this and override
                // the values of pagedDataSource to achieve the custom paging using the default pager supplied
                CreateNumericPager(row, pagedDataSource, columnSpan, true);
            }
            else
                base.InitializePager(row, columnSpan, pagedDataSource);
        }

        /// <summary>
        /// Gets or sets the first index of the displayed page.
        /// </summary>
        /// <value>The first index of the displayed page.</value>
        private int FirstDisplayedPageIndex
        {
            get
            {
                object obj2 = ViewState["FirstDisplayedPageIndex"];
                if (obj2 != null)
                {
                    return (int)obj2;
                }
                return -1;
            }
            set
            {
                ViewState["FirstDisplayedPageIndex"] = value;
            }
        }

        /// <summary>
        /// Creates the numeric pager.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="pagedDataSource">The paged data source.</param>
        /// <param name="columnSpan">The column span.</param>
        /// <param name="addFirstLastPageButtons">if set to <c>true</c> [add first last page buttons].</param>
        private void CreateNumericPager(TableRow row, PagedDataSource pagedDataSource, int columnSpan, bool addFirstLastPageButtons)
        {
            PagerSettings pagerSettings = PagerSettings;
            bool isFirstPage = pagedDataSource.IsFirstPage;
            bool isLastPage = pagedDataSource.IsLastPage;

            int pageCount = pagedDataSource.PageCount;
            int num2 = pagedDataSource.CurrentPageIndex + 1;
            int pageButtonCount = pagerSettings.PageButtonCount;
            int num4 = pageButtonCount;
            int num5 = FirstDisplayedPageIndex + 1;
            if (pageCount < num4)
            {
                num4 = pageCount;
            }
            int num6 = 1;
            int pageIndex = num4;
            if (num2 > pageIndex)
            {
                int num8 = pagedDataSource.CurrentPageIndex / pageButtonCount;
                bool flag = ((num2 - num5) >= 0) && ((num2 - num5) < pageButtonCount);
                if ((num5 > 0) && flag)
                {
                    num6 = num5;
                }
                else
                {
                    num6 = (num8 * pageButtonCount) + 1;
                }
                pageIndex = (num6 + pageButtonCount) - 1;
                if (pageIndex > pageCount)
                {
                    pageIndex = pageCount;
                }
                if (((pageIndex - num6) + 1) < pageButtonCount)
                {
                    num6 = Math.Max(1, (pageIndex - pageButtonCount) + 1);
                }
                FirstDisplayedPageIndex = num6 - 1;
            }

            TableCell cell = new TableCell();
            cell.ColumnSpan = columnSpan;
            cell.Width = Unit.Percentage(100);
            cell.Height = Unit.Pixel(20);
            cell.CssClass = PagerStyle.CssClass;

            row.Cells.Add(cell);

            Table tbl = new Table();
            TableRow tr = new TableRow();
            tbl.Rows.Add(tr);
            cell.Controls.Add(tbl);
            DataControlLinkButton dataControlLinkButton;


            if ((addFirstLastPageButtons && (num2 != 1)) && (num6 != 1))
            {
                dataControlLinkButton = new DataControlLinkButton(this);
                dataControlLinkButton.Text = pagerSettings.FirstPageText;
                dataControlLinkButton.EnableCallback(BuildCallbackArgument(0));
                dataControlLinkButton.CommandName = "Page";
                dataControlLinkButton.CommandArgument = "First";
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(dataControlLinkButton);

            }

            if (!isFirstPage)
            {
                dataControlLinkButton = new DataControlLinkButton(this);
                dataControlLinkButton.Text = pagerSettings.PreviousPageText;
                dataControlLinkButton.EnableCallback(BuildCallbackArgument(pagedDataSource.CurrentPageIndex + 1));
                dataControlLinkButton.CommandName = "Page";
                dataControlLinkButton.CommandArgument = (pagedDataSource.CurrentPageIndex).ToString(NumberFormatInfo.InvariantInfo);
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(dataControlLinkButton);
            }
            else
            {
                Label child = new Label();
                child.Text = pagerSettings.PreviousPageText;
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(child);
            }

            if (num6 != 1)
            {
                dataControlLinkButton = new DataControlLinkButton(this);
                dataControlLinkButton.Text = "...";
                dataControlLinkButton.CommandName = "Page";
                dataControlLinkButton.CommandArgument = (num6 - 1).ToString(NumberFormatInfo.InvariantInfo);
                dataControlLinkButton.EnableCallback(BuildCallbackArgument(num6 - 2));
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(dataControlLinkButton);

            }

            for (int i = num6; i <= pageIndex; i++)
            {
                string str2 = i.ToString(NumberFormatInfo.InvariantInfo);
                if (i == num2)
                {
                    Label child = new Label();
                    child.Text = str2;
                    cell = new TableCell();
                    tr.Cells.Add(cell);
                    cell.Controls.Add(child);
                }
                else
                {
                    dataControlLinkButton = new DataControlLinkButton(this);
                    dataControlLinkButton.Text = str2;
                    dataControlLinkButton.CommandName = "Page";
                    dataControlLinkButton.CommandArgument = str2;
                    dataControlLinkButton.EnableCallback(BuildCallbackArgument(i - 1));
                    cell = new TableCell();
                    tr.Cells.Add(cell);
                    cell.Controls.Add(dataControlLinkButton);
                }
            }
            if (pageCount > pageIndex)
            {
                dataControlLinkButton = new DataControlLinkButton(this);
                dataControlLinkButton.Text = "...";
                dataControlLinkButton.CommandName = "Page";
                dataControlLinkButton.CommandArgument = (pageIndex + 1).ToString(NumberFormatInfo.InvariantInfo);
                dataControlLinkButton.EnableCallback(BuildCallbackArgument(pageIndex));
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(dataControlLinkButton);

            }
            bool flag2 = pageIndex == pageCount;
            if ((addFirstLastPageButtons && (num2 != pageCount)) && !flag2)
            {
                dataControlLinkButton = new DataControlLinkButton(this);
                dataControlLinkButton.Text = pagerSettings.LastPageText;
                dataControlLinkButton.EnableCallback(BuildCallbackArgument(pagedDataSource.PageCount - 1));
                dataControlLinkButton.CommandName = "Page";
                dataControlLinkButton.CommandArgument = "Last";
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(dataControlLinkButton);

            }

            if (!isLastPage)
            {
                dataControlLinkButton = new DataControlLinkButton(this);
                dataControlLinkButton.Text = pagerSettings.NextPageText;
                dataControlLinkButton.EnableCallback(BuildCallbackArgument(pagedDataSource.CurrentPageIndex + 1));
                dataControlLinkButton.CommandName = "Page";
                dataControlLinkButton.CommandArgument = (pagedDataSource.CurrentPageIndex + 2).ToString(NumberFormatInfo.InvariantInfo); ;
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(dataControlLinkButton);
            }
            else
            {
                Label child = new Label();
                child.Text = pagerSettings.NextPageText;
                cell = new TableCell();
                tr.Cells.Add(cell);
                cell.Controls.Add(child);
            }
        }

        /// <summary>
        /// Builds the callback argument.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <returns></returns>
        private string BuildCallbackArgument(int pageIndex)
        {
            return string.Concat(new object[] { "\"", pageIndex, "|", (int)SortDirection, "|", "", "|\"" });
        }

        #region Custom properties

        [Category("Behaviour")]
        [Bindable(BindableSupport.No)]
        [Description("Show or Hide Column Fill in the DropDown")]
        public string ShowHideDropDown
        {
            get
            {
                object value = ViewState["ShowHideDropDown"];

                if (value != null)
                {
                    return value.ToString();
                }

                return string.Empty;
            }

            set
            {
                ViewState["ShowHideDropDown"] = value;
            }
        }

        [Category("Behaviour")]
        [Bindable(BindableSupport.No)]
        [Description("Search Panel")]
        public string SearchPanel
        {
            get
            {
                object value = ViewState["SearchPanel"];

                if (value != null)
                {
                    return value.ToString();
                }

                return string.Empty;
            }

            set
            {
                ViewState["SearchPanel"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [show when empty].
        /// </summary>
        /// <value><c>true</c> if [show when empty]; otherwise, <c>false</c>.</value>
        [Category("Behaviour")]
        [Themeable(true)]
        [Bindable(BindableSupport.No)]
        [DefaultValue(true)]
        public bool ShowWhenEmpty
        {
            get
            {
                if (ViewState["ShowWhenEmpty"] == null)
                    ViewState["ShowWhenEmpty"] = true;

                return (bool)ViewState["ShowWhenEmpty"];
            }
            set
            {
                ViewState["ShowWhenEmpty"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the virtual item count.
        /// </summary>
        /// <value>The virtual item count.</value>
        [Description("Set the virtual item count for this grid")]
        public int VirtualItemCount
        {
            get
            {
                if (ViewState["pgv_vitemcount"] == null)
                    ViewState["pgv_vitemcount"] = -1;
                return Convert.ToInt32(ViewState["pgv_vitemcount"]);
            }
            set
            {
                ViewState["pgv_vitemcount"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [use custom pager].
        /// </summary>
        /// <value><c>true</c> if [use custom pager]; otherwise, <c>false</c>.</value>
        [Browsable(true), Category("Paging")]
        [Description("Allow to use custom paging")]
        public bool UseCustomPager
        {
            get { return (bool?)ViewState["UseCustomPager"] ?? false; }
            set { ViewState["UseCustomPager"] = value; }
        }

        /// <summary>
        /// Gets or sets the index of the current page.
        /// </summary>
        /// <value>The index of the current page.</value>
        private int CurrentPageIndex
        {
            get
            {
                if (ViewState["pgv_pageindex"] == null)
                    ViewState["pgv_pageindex"] = 0;
                return Convert.ToInt32(ViewState["pgv_pageindex"]);
            }
            set
            {
                ViewState["pgv_pageindex"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the object from which the data-bound control retrieves its list of data items.
        /// </summary>
        /// <value></value>
        /// <returns>
        /// An object that represents the data source from which the data-bound control retrieves its data. The default is null.
        /// </returns>
        public override object DataSource
        {
            get
            {
                return base.DataSource;
            }
            set
            {
                base.DataSource = value;
                // we store the page index here so we dont lost it in databind
                CurrentPageIndex = PageIndex;
            }
        }
        #endregion
    }
}